package com.lovo.frame;

import com.lovo.pojo.UserDO;
import com.lovo.util.GetConnectionUtil;
import com.lovo.util.Util;


import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class Mainjframe extends JFrame {
    private CardLayout cardLayout = new CardLayout();
    private ArrayList<UserDO> users = new ArrayList<>();
    private int index;
    private Loginjpanel loginjpanel = new Loginjpanel(this);
    private Menujpanel menujpanel = new Menujpanel(this);
    private Savejpanel savejpanel = new Savejpanel(this);
    private Getjpanel getjpanel = new Getjpanel(this);
    private Findjpanel findjpanel = new Findjpanel(this);
    private Transferjpanel transferjpanel = new Transferjpanel(this);
    private Modifyjpanel modifyjpanel = new Modifyjpanel(this);
    private Zhucejpanel zhucejpanel = new Zhucejpanel(this);
    private Image bgimage = Util.getImage("/images/background.jpg");
    private GetConnectionUtil g = new GetConnectionUtil();
    private UserDO LoginUser;

    public Mainjframe() {
        init();
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimage, 0, 0, 1200, 800, this);
            }
        });
        this.setLayout(cardLayout);
        this.add("login", loginjpanel);
        this.add("menu", menujpanel);
        this.add("Save", savejpanel);
        this.add("Get", getjpanel);
        this.add("Find", findjpanel);
        this.add("Transfer", transferjpanel);
        this.add("Modify", modifyjpanel);
        this.add("Zhuce",zhucejpanel);
        this.setSize(1200, 800);
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
    }

    //初始化账户
    public void init() {
        List userlist = g.query();
        if(userlist.size() == 0){
            g.insert("zhangsan", "123", 1000);
            g.insert("lisi", "456", 2000);
            g.insert("wangwu", "789", 3000);
        }
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    public static void main(String[] args) {
        new Mainjframe();
    }

    public ArrayList<UserDO> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<UserDO> users) {
        this.users = users;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Savejpanel getSavejpanel() {
        return savejpanel;
    }

    public void setSavejpanel(Savejpanel savejpanel) {
        this.savejpanel = savejpanel;
    }

    public Getjpanel getGetjpanel() {
        return getjpanel;
    }

    public void setGetjpanel(Getjpanel getjpanel) {
        this.getjpanel = getjpanel;
    }

    public Findjpanel getFindjpanel() {
        return findjpanel;
    }

    public void setFindjpanel(Findjpanel findjpanel) {
        this.findjpanel = findjpanel;
    }

    public Transferjpanel getTransferjpanel() {
        return transferjpanel;
    }

    public void setTransferjpanel(Transferjpanel transferjpanel) {
        this.transferjpanel = transferjpanel;
    }

    public Modifyjpanel getModifyjpanel() {
        return modifyjpanel;
    }

    public void setModifyjpanel(Modifyjpanel modifyjpanel) {
        this.modifyjpanel = modifyjpanel;
    }

    public Loginjpanel getLoginjpanel() {
        return loginjpanel;
    }

    public void setLoginjpanel(Loginjpanel loginjpanel) {
        this.loginjpanel = loginjpanel;
    }

    public GetConnectionUtil getG() {
        return g;
    }

    public void setG(GetConnectionUtil g) {
        this.g = g;
    }

    public UserDO getLoginUser() {
        return LoginUser;
    }

    public void setLoginUser(UserDO loginUser) {
        LoginUser = loginUser;
    }
}
